package cn.buk.tms.dao;

import cn.buk.tms.entity.misc.OperationLog;
import cn.buk.tms.entity.bill.SettlementSheet;
import cn.buk.tms.sc.SearchSettlementCriteria;

import java.util.List;

/**
 * 结算单相关的数据库操作
 *
 * @author yfdai
 */
public interface SettlementDao {

  /**
   * 新建或加入结算单
   */
  int createSettlement(int enterpriseId, String username, int customerId, int settlementId, String settlementNo,
                       String settlementName, double total, Integer[] billIds, String remark);

  /**
   * 查找结算单
   *
   * @param enterpriseId       企业id
   * @param sc                 查找条件
   * @param allowedCustomerIds
   * @return 结算单列表
   */
  List<SettlementSheet> searchSettlements(int enterpriseId, SearchSettlementCriteria sc, List<Integer> allowedCustomerIds);

  List<SettlementSheet> searchUnpaidSettlements(int enterpriseId, int customerId);

  SettlementSheet getSettlementSheetById(int id);

  SettlementSheet getSettlementSheetByNo(int enterpriseId, String settlementNo);

  List<OperationLog> searchSettlementHistory(int enterpriseId, int settlementId);

  int adjustSettlementAmount(int enterpriseId, String username, int id, double amount, String remark);

  int updateSettlementName(int enterpriseId, String username, int id, String settlementName);

  /**
   * 从结算单中移除指定账单
   *
   * @param enterpriseId 企业id
   * @param username     用户名
   * @param settlementId 结算单id
   * @param billNo       账单号
   * @return
   */
  int removeBillOfSettlement(final int enterpriseId, final String username, final int settlementId, final String billNo);


  /**
   * 对金额为0的结算单做销账操作
   *
   * @param enterpriseId 企业id
   * @param username     当前用户名
   * @param settlementId 结算单id
   * @return
   */
  int writeOffZeroSettlementAmount(int enterpriseId, String username, int settlementId);

  int writeOffSettlement(int enterpriseId, String username, int settlementId, int receiptId);


  int undoWriteOffSettlement(int enterpriseId, String username, int settlementId);

  /**
   * 移除结算单中的所有账单
   * @param enterpriseId
   * @param username
   * @param settlementId 结算单id
   * @return
   */
  int removeAllBills(int enterpriseId, String username, int settlementId);
}
